package com.qiaomengapp.dao;


import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.qiaomengapp.bean.Shop;
import com.qiaomengapp.bean.ShopWarp;

public interface ShopMapper {
	//首先根据id查询表中是否具有相应的shop对象，用该对象进行错误处理
	@Select("select id from shop where id=#{value}")
	Shop select_ShopById(int id);
	//然后查询可用佣金和累计佣金
	@Select("select sum_commission from shop where id=#{value}")
	double select_sum_commission(int id);
	@Select("select able_commission from shop where id=#{value}")
	double select_able_commission(int id);
	//更改商店的佣金进出情况`
	//增加总的佣金
	@Update("update shop set sum_commission=sum_commission+#{sum} where id=#{id}")
	int update_sum_addCommission(@Param("sum")double sum,@Param("id")double id);
	//减少总佣金
	@Update("update shop set sum_commission=sum_commission-#{sum} where id=#{id} and sum_commission>=#{sum}")
	int update_sum_reduceCommission(@Param("sum")double sum,@Param("id")double id);
	//更改可用提现佣金
	@Update("update shop set able_commission=able_commission+#{value} where id=#{id}")
	int update_able_addCommission(@Param("value")double value,@Param("id")double id);
	//可用佣金应该大于减少的佣金
	@Update("update shop set able_commission=able_commission-#{value} where id=#{id} and able_commission>=#{value}")
	int update_able_reduceCommission(@Param("value")double sum,@Param("id")double id);
	
	//店铺预览，根据id选择出相应的要显示在页面的shop
	//字段：shop_name,shop_titleUrl,shop_level,shop_cityid,全部宝贝为shop_good中的所有商品数量,上新为在一定时间内上架的商品
	//再连shop_good表得到gooddesc,goodimgurl
	ShopWarp select_shopByIdForSee(int id);
	
	//根据用户id查询商铺
	ShopWarp select_shopByUid(int uid);
	
	//根据shopName来搜索店铺,显示店铺总销量，总商品数量，shopName,shopUrl,shopLevel
	//shop_good表中的3个商品goodUrl,price
	List<ShopWarp> select_shopByShopName(String shopName);
	
}
